package com.molyfun.parents.push;

/**
 * Created by william(liuchao.hit@gmail.com).
 * Date:12/16/16.
 *
 * single model
 *
 * cache last msg info
 */
public class PushMsgCacheCenter {

    private String mCurrentTopMsg;
    private String mCurrentDetailId;

    private int mCurrentUnreadCount = 0;

    private PushMsgCacheCenter(){}

    private static PushMsgCacheCenter mInstance;

    public static PushMsgCacheCenter getInstance(){
        if(mInstance == null){
            mInstance = new PushMsgCacheCenter();
        }
        return mInstance;
    }

    public void putPushMsg(String msg, String detailId){
        this.mCurrentTopMsg = msg;
        this.mCurrentDetailId = detailId;
        if(mPushMsgCallback != null){
            mPushMsgCallback.onMsgReceive();
        }
    }

    public String getPushMsg(){
        return mCurrentTopMsg;
    }

    public String getPushDetailId(){
        return mCurrentDetailId;
    }

    public void clearMsg(){
        mCurrentTopMsg = null;
        mCurrentDetailId = null;
    }

    private PushMsgCallback mPushMsgCallback;

    public void registerPushMsgCallback(PushMsgCallback pushMsgCallback){
        this.mPushMsgCallback = pushMsgCallback;
    }

    public void unregisterPushCallback(){
        this.mPushMsgCallback = null;
    }

    /**
     * to show msg in mainTab when msg receive
     */
    public interface PushMsgCallback{
        void onMsgReceive();
    }

    public int getmCurrentUnreadCount() {
        return mCurrentUnreadCount;
    }

    public void setmCurrentUnreadCount(int mCurrentUnreadCount) {
        this.mCurrentUnreadCount = mCurrentUnreadCount;
    }

    public void unReadCountPlus(){
        mCurrentUnreadCount ++;
    }

    public void unReadCountMinus(){
        if(mCurrentUnreadCount > 0){
            mCurrentUnreadCount --;
        }
    }
}
